package com.jiashihui.schema_lgorithm.schema.proxy;

import java.lang.reflect.Proxy;

/**
 * @author jiashihui
 * @describe: 动态代理
 * @date 2019/03/14
 */
public class JDKProxy {

    @SuppressWarnings("unchecked")
    public <T> T bind(T t) {
        return (T) Proxy.newProxyInstance(t.getClass().getClassLoader(), t.getClass().getInterfaces(), (proxy, method, args) -> {
            System.out.println("===代理前===");
            Object result = method.invoke(t, args);
            System.out.println("===代理后===");
            return result;
        });
    }
}
